/**
 * @file ABs.h
 * @brief 
 * @author Linhuo (1066117119@qq.com)
 * @version 1.0
 * @date 2021-04-26
 * 
 * @copyright Copyright (c) 2021  Linhuo
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2021-04-26 <td>1.0     <td>Linhuo     <td>内容
 * </table>
 */
#ifndef _solution_ERK_
#define _solution_ERK_

#include "TimeIntegrator.h"

class ERK4: public TimeIntegrator
{
public:
    void load_scheme(std::string _name);
    void initial_value(Eigen::VectorXd _u0);
    void One_step_forward();    
};


void ERK4::One_step_forward()
{
    Eigen::VectorXd y_1,y_2,y_3,y_4;
   
    y_1 = func(u.col(0));
    y_2 = func(u.col(0) + 0.5 * dt * y_1 );
    y_3 = func(u.col(0) + 0.5 * dt * y_2 );
    y_4 = func(u.col(0) + dt * y_3);

    u.col(0) = u.col(0) + (dt / 6.0) * (y_1 + 2 * y_2 + 2 * y_3 + y_4 );

};

void ERK4::load_scheme(std::string _name)
{
    name = "ERK4";
    s = 1;
    p = 4;
    dt = 0.005;
};

void ERK4::initial_value(Eigen::VectorXd _u0)
{   
    u.resize(6,s);
    fu.resize(6,s);
    u.col(0) = _u0;
};

#else
//DO NOTHING
#endif